
#include<iostream>
#include "renderer.hpp"
#include "vertex_array.hpp"
#include "index_buffer.hpp"
#include "shader.hpp"

using namespace std;

void GLClearError() {
    while ( glGetError() != GL_NO_ERROR ) {
    }
}

mb GLLogCall( char const * function, char const * file, int line ) {
    while ( GLenum error = glGetError() ) {
        cout << "[OPENGL ERROR]" << "(" << error << "):";
        cout << function << " " << file << ":" << line << endl;
        return 0;
    }
    return 1;
}

void Renderer::clean()
{
    glClear( GL_COLOR_BUFFER_BIT );
}

void Renderer::draw( VertexArray const & va, IndexBuffer const & ib, Shader const & shader )
{
    va.bind();
    ib.bind();
    shader.bind();

    GLCall( glDrawElements( GL_TRIANGLES, ib.count(), GL_UNSIGNED_INT, nullptr ) );
}

//void Renderer::init()
//{
//}
//
//void Renderer::shutdown()
//{
//}
//
//void Renderer::begin()
//{
//}
//
//void Renderer::end()
//{
//}
//
//void Renderer::flush()
//{
//}
//
//void Renderer::drawQuad( glm::vec2 const & position, glm::vec2 const & size, glm::vec4 const & color )
//{
//}
//void Renderer::drawQuad( glm::vec2 const & position, glm::vec2 const & size, unsigned int textureID )
//{
//}
//
//Renderer::Stats & Renderer::getStats()
//{
//    return Renderer::Stats();
//}
//
//void Renderer::rersetStats()
//{
//}
